package com.example.java.repository;

import com.example.java.pojo.User;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository //定义对数据库操作接口
public interface UserRepository extends CrudRepository<User,Integer> {
    //根据手机号查询，返回值为1或者0
    @Query(value = "SELECT EXISTS(SELECT 1 FROM cb_user WHERE phone = ?1) AS phone_exists", nativeQuery = true)
    int findByPhone(String phone);

    //根据手机号查询，返回值为整个对象
    @Query(value = "SELECT * FROM cb_user WHERE phone = ?1", nativeQuery = true)
    User findByPhoneReturnAll(String phone);
}
